package smashedapples.google
{
	import smashedapples.core.Command;
	import smashedapples.google.language.GoogleLanguageRequest;
	import smashedapples.google.language.LangPairVO;
	import smashedapples.google.language.LanguageVO;
	
	/**
	 * 
	 *  Flex Api to Access Google Language Api
	 *  http://code.google.com/apis/ajaxlanguage/documentation/
	 * 
	 * @author brian holmes
	 * @email brian.joseph31 at gmail
	 */	
	public class GoogleLanguageApi
	{		
		
		 /**
		  *  @private static instance 
		  */		
		 private static var _static : GoogleLanguageApi;
		 
		 
		 
		 public static function get Static():GoogleLanguageApi
		 {
		 	if( GoogleLanguageApi.Static == null)
		 		GoogleLanguageApi.Static = new GoogleLanguageApi();
		 	return GoogleLanguageApi.Static;
		 }
		 
		 public static function set Static(value : GoogleLanguageApi):void
		 {
		 	GoogleLanguageApi._static = value;
		 }
		
		
		 /**
		  * static var that points to the Google Language Api Endpoint  
		  */		
		 public var URL : String = "http://ajax.googleapis.com/ajax/services/language/translate";	
		
		 
		 public var ARABIC : LanguageVO = new LanguageVO("ar","Arabic");
		 public var CHINESE : LanguageVO = new LanguageVO("zh","Chinese");
		 public var CHINESE_SIMPLIFIED : LanguageVO = new LanguageVO("zh-CN","Chinese Simplified");
		 public var CHINESE_TRADITIONAL : LanguageVO = new LanguageVO("zh-TW","Chinese Traditional");
		 public var DUTCH : LanguageVO = new LanguageVO("nl","Dutch");	
		 public var ENGLISH : LanguageVO = new LanguageVO("en","English");
		 public var FRENCH : LanguageVO = new LanguageVO("fr","French");	
		 public var GERMAN : LanguageVO = new LanguageVO("de","German");
		 public var GREEK : LanguageVO = new LanguageVO("el","Greek");
		 public var ITALIAN : LanguageVO = new LanguageVO("it","Italian");
		 public var JAPANESE : LanguageVO = new LanguageVO("ja","Japanese");
		 public var KOREAN : LanguageVO = new LanguageVO("ko","Korean");
		 public var PORTUGESE : LanguageVO = new LanguageVO("pt","Portugese");
		 public var RUSSIAN : LanguageVO = new LanguageVO("ru","Russian");
		 public var SPANISH : LanguageVO = new LanguageVO("es","Spanish");
		 
		 
		public function getLangByCode(langCode:String):LanguageVO
		{
			
			for each( var language : LanguageVO in this.languages )
			{
				if( language.langCode == langCode )
					return language;
			}
		
			return ENGLISH;
		}
		 
		private var _languages : Array;

        public function get languages() : Array
        {
        	
        	if(_languages != null)
        		return _languages;
        	
    		_languages = [];
    		
    		_languages.push( ARABIC );
    		_languages.push( CHINESE );
    		_languages.push( CHINESE_SIMPLIFIED );
    		_languages.push( CHINESE_TRADITIONAL );
    		_languages.push( DUTCH );
    		_languages.push( ENGLISH );
    		_languages.push( FRENCH );
    		_languages.push( GERMAN );
    		_languages.push( GREEK );
    		_languages.push( ITALIAN );
    		_languages.push( JAPANESE );
    		_languages.push( KOREAN );
    		_languages.push( PORTUGESE );
    		_languages.push( RUSSIAN );
    		_languages.push( SPANISH );

        	return _languages;
        }
		
		
		/**
		 * private  
		 */		 
		private var _languagePairs : Array;           
        
        
        /**
         *  language pairs supported by Google
         * @return array 
         * 
         */        
        public function get languagePairs() : Array
        {
        	if(_languagePairs != null)
        		return _languagePairs;
        	
    		_languagePairs = [];
    		
    		_languagePairs.push( new LangPairVO(ENGLISH,ARABIC) );
    		_languagePairs.push( new LangPairVO(ENGLISH,CHINESE) );
    		_languagePairs.push( new LangPairVO(ENGLISH,CHINESE_SIMPLIFIED) );
    		_languagePairs.push( new LangPairVO(ENGLISH,CHINESE_TRADITIONAL) );
    		_languagePairs.push( new LangPairVO(ENGLISH,DUTCH) );
    		_languagePairs.push( new LangPairVO(ENGLISH,FRENCH) );
    		_languagePairs.push( new LangPairVO(ENGLISH,GERMAN) );
    		_languagePairs.push( new LangPairVO(ENGLISH,GREEK) );
    		_languagePairs.push( new LangPairVO(ENGLISH,ITALIAN) );
    		_languagePairs.push( new LangPairVO(ENGLISH,JAPANESE) );
    		_languagePairs.push( new LangPairVO(ENGLISH,KOREAN) );
    		_languagePairs.push( new LangPairVO(ENGLISH,PORTUGESE) );
    		_languagePairs.push( new LangPairVO(ENGLISH,RUSSIAN) );
    		_languagePairs.push( new LangPairVO(ENGLISH,SPANISH) );
    		
    		_languagePairs.push( new LangPairVO(ARABIC,ENGLISH) );
    		_languagePairs.push( new LangPairVO(CHINESE,ENGLISH) );
    		_languagePairs.push( new LangPairVO(CHINESE_SIMPLIFIED,CHINESE_TRADITIONAL) );
    		_languagePairs.push( new LangPairVO(CHINESE_TRADITIONAL,CHINESE_SIMPLIFIED) );
    		_languagePairs.push( new LangPairVO(DUTCH,ENGLISH) );
    		
    		_languagePairs.push( new LangPairVO(FRENCH,GERMAN) );
    		_languagePairs.push( new LangPairVO(FRENCH,KOREAN) );
    		_languagePairs.push( new LangPairVO(GERMAN,ENGLISH) );
    		_languagePairs.push( new LangPairVO(GERMAN,FRENCH) );
    		
    		_languagePairs.push( new LangPairVO(GREEK,ENGLISH) );
    		_languagePairs.push( new LangPairVO(ITALIAN,ENGLISH) );
    		_languagePairs.push( new LangPairVO(JAPANESE,ENGLISH) );
    		_languagePairs.push( new LangPairVO(KOREAN,ENGLISH) );
    		_languagePairs.push( new LangPairVO(PORTUGESE,ENGLISH) );
    		
    		_languagePairs.push( new LangPairVO(RUSSIAN,ENGLISH) );
    		_languagePairs.push( new LangPairVO(SPANISH,ENGLISH) );
      
        	
        	return _languagePairs;
        } 
		 
	
		  
		 public function createRequest(command:Command,text:String,langPair:LangPairVO,
		 								  result:Function,fault:Function=null):GoogleLanguageRequest
		 {
			return new GoogleLanguageRequest(command,text,langPair, result,fault);
		 } 
		
		 

	}
}